﻿using LiteDB;

namespace EduAssess.Services;

public class Repository(ILiteDatabase database)
{
    public void Save<T>(T item)
    {
        GetCollection<T>().Upsert(item);
    }

    public T Get<T>(Guid id) => GetCollection<T>().FindById(id);

    public void Delete<T>(Guid id)
    { 
        GetCollection<T>().Delete(id);
    }

    public IEnumerable<T> FindAll<T>() => GetCollection<T>().FindAll();


    private ILiteCollection<T> GetCollection<T>() => database.GetCollection<T>();
}